package com.situ.day10;

//实体类：和数据库表一一对应
// 类：大驼峰  StudentManager
// 变量、属性、方法：小驼峰   getInfo()
public class Student extends Object{
    //属性、字段  Field
    //default
    private int id;
    private String name;
    //私有属性和方法，只能在类内部访问
    private int age;
    private String gender;//男、女

    //无参构造方法
    //如果不写，Java默认提供这样一个无参构造方法.
    //如果你写了任何一个构造方法，Java就不会再提供这个无参构造方法
    public Student() {
        //soutm
        System.out.println("Student.Student1");
    }

    //有参构造方法
    public Student(int id, String name, int age, String gender) {
        System.out.println("Student.Student2");
        this.id = id;
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public void setAge(int age) {
        //Variable 'age' is assigned to itself
        //就近原则
        //age = age;
        //this:代表当前对象
        if (age > 0 && age <= 130) {
            this.age = age;
        }
    }

    public int getAge() {
        //return this.age;
        return age;
    }


    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                '}';
    }

    //方法、函数  动作   Method
    public String getInfo() {
        //String str = "[Student: id=1,name=zhangsan,age=23,gender=男]";
        String str = "[Student: id="+id+",name="+name+",age="+age+",gender="+gender+"]";
        return str;
    }

}
